package com.tarena.lbs.article.web.service;

import com.tarena.lbs.article.web.dao.repository.ArticleCategoryRepository;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.pojo.basic.po.ArticleCategoryPO;
import com.tarena.lbs.pojo.content.vo.ArticleCategoryVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ArticleCategoryService {
    @Autowired
    private ArticleCategoryRepository articleCategoryRepository;

    public PageResult<ArticleCategoryVO> categoryPage() {
        //1.准备一个pageResult pageNo pageSize total写死
        PageResult<ArticleCategoryVO> voPage=new PageResult<>(1,10);
        voPage.setTotal(100L);
        //2.查询所有 分类 封装 返回
        List<ArticleCategoryPO> pos = articleCategoryRepository.list();
        List<ArticleCategoryVO> vos = pos.stream().map(po -> {
            ArticleCategoryVO vo = new ArticleCategoryVO();
            BeanUtils.copyProperties(po, vo);
            return vo;
        }).collect(Collectors.toList());
        voPage.setObjects(vos);
        return voPage;
    }
}
